package BandB.Tool.GPhoneManager.FileExplorer.Util;

import java.io.File;

import BandB.Tool.GPhoneManager.R;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;

public class IconFactory {
	private Drawable fileIcon;
	private Drawable musicIcon;
	private Drawable pictureIcon;
	private Drawable folderIcon;
	private Drawable apkIcon;
	private static IconFactory instance;

	private IconFactory(Context context) {
		// TODO Auto-generated constructor stub
		Resources res = context.getResources();
		fileIcon = res.getDrawable(R.drawable.file);
		pictureIcon = res.getDrawable(R.drawable.picture);
		musicIcon = res.getDrawable(R.drawable.music);
		folderIcon = res.getDrawable(R.drawable.folder);
		apkIcon = res.getDrawable(R.drawable.market);
	}

	public static IconFactory getInstance(Context context) {
		if (instance == null) {
			instance = new IconFactory(context);
		}
		return instance;
	}

	public Drawable getFileIcon(File file) {
		if (file == null) {
			return null;
		}
		if (file.isDirectory()) {
			return getFolderIcon();
		} else {
			return getIconFromExt(Utilities.getFileExtension(file));
		}
	}

	public Drawable getFolderIcon() {
		return folderIcon;
	}

	public Drawable getIconFromExt(String ext) {
		if (ext.equalsIgnoreCase(".jpg") || ext.equalsIgnoreCase(".gif")
				|| ext.equalsIgnoreCase(".png") || ext.equalsIgnoreCase(".bmp")) {
			return pictureIcon;
		} else if (ext.equalsIgnoreCase(".mp3") || ext.equalsIgnoreCase(".ogg")
				|| ext.equalsIgnoreCase(".wav") || ext.equalsIgnoreCase(".3gp")
				|| ext.equalsIgnoreCase(".mp4")) {
			return musicIcon;
		} else if (ext.equalsIgnoreCase(".apk")) {
			return apkIcon;
		} else {
			return fileIcon;
		}
	}
}
